package com.szh.cloud.api.teacher.control;

import com.szh.cloud.api.teacher.entity.SearTeacherEntity;
import com.szh.cloud.api.teacher.service.ApiTeacherService;
import com.szh.cloud.mybatis.entity.PtTeacherEntity;
import com.szh.cloud.mybatis.etable.ElTable;
import com.szh.cloud.mybatis.flexigrid.PagingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/teacher")
public class ApiTeacherControl {
    @Autowired
    private ApiTeacherService teacherService;

    @PostMapping("/query")
    public ResponseEntity<Map<String, Object>> queryTeachers(@RequestBody SearTeacherEntity params) {
        return ResponseEntity.ok(teacherService.queryTeachers(params));
    }

    @GetMapping("/{tchrUuid}")
    public ResponseEntity<SearTeacherEntity> getTeacher(@PathVariable String tchrUuid) {
        return ResponseEntity.ok(teacherService.getTeacherById(tchrUuid));
    }

    @PostMapping
    public ResponseEntity<Boolean> addTeacher(@RequestBody SearTeacherEntity teacher) {
        return ResponseEntity.ok(teacherService.addTeacher(teacher));
    }

    @PutMapping("/{tchrUuid}")
    public ResponseEntity<Boolean> updateTeacher(@PathVariable String tchrUuid,
                                                 @RequestBody SearTeacherEntity teacher) {
        teacher.setTchrUuid(tchrUuid);
        return ResponseEntity.ok(teacherService.updateTeacher(teacher));
    }

    @DeleteMapping("/{tchrUuid}")
    public ResponseEntity<Boolean> deleteTeacher(@PathVariable String tchrUuid) {
        return ResponseEntity.ok(teacherService.deleteTeacher(tchrUuid));
    }

    @DeleteMapping("/batch")
    public ResponseEntity<Boolean> batchDeleteTeachers(@RequestBody Map<String, List<String>> params) {
        return ResponseEntity.ok(teacherService.batchDeleteTeachers(params.get("ids")));
    }
}
